local tunxing = fk.CreateSkill {

  name = "joy__tunxing",

  tags = { Skill.Compulsory, },

}



tunxing:addEffect(fk.GameStart, {
  name = "joy__tunxing",
  anim_type = "special",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.GameStart,"fk.joy__tunxing"},
  can_trigger = function(self, event, target, player, data)
    if event == fk.GameStart then
      return player:hasSkill(tunxing.name) 
    else
      return target == player and player:hasSkill(tunxing.name) 
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local mark = type(player:getMark(tunxing.name)) == "table" and player:getMark(tunxing.name) or {}
    if #mark > 0 then
      for _, s in ipairs(mark) do
        room:handleAddLoseSkills(player,"-"..s)
      end
    end
    local lords = {}
    local gp = table.simpleClone(Fk:getAllGenerals())
    table.shuffle(gp)
    for _, general in ipairs(gp) do
      if #lords >= 3 then break end
      for _, s in ipairs(general.skills) do
        if s.lordSkill then
          table.insertIfNeed(lords,general.name)
        end
      end
    end
    local choice
    local result = player.room:askForCustomDialog(player, tunxing.name,
      "packages/utility/qml/ChooseGeneralsAndChoiceBox.qml", {
        lords,
        {"OK"},
        "选择一张武将牌获得其除限定技、主公技外的所有技能",
      })
      if result ~= "" then
        local reply = json.decode(result)
        choice = reply.cards[1]
      end
    mark = {}
    if choice and Fk.generals[choice] ~= nil then
    local skills = table.simpleClone(Fk.generals[choice].skills)
    local skills2 = table.simpleClone(Fk.generals[choice].other_skills)
    if #skills2 > 0 then
      for _, s in ipairs(skills2) do
        table.insertIfNeed(skills,s)
      end
    end
    for _, s in ipairs(skills) do
        if not (table.contains({Skill.Limited, Skill.Wake, Skill.Quest},s.frequency) or s.lordSkill) and not player:hasSkill(s.name) then
          table.insertIfNeed(mark,s.name)
        end
    end
    room:notifySkillInvoked(player,tunxing.name)
    player:broadcastSkillInvoke(tunxing.name)
    room:setPlayerMark(player,tunxing.name,mark)
    room:handleAddLoseSkills(player,table.concat(mark,"|"))
    end
  end,
})
--[[睿智北冰洋
tunxing:addEffect("fk.joy__tunxing", {
  name = "joy__tunxing",
  anim_type = "special",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.GameStart,"fk.joy__tunxing"},
  can_trigger = function(self, event, target, player, data)
    if event == fk.GameStart then
      return player:hasSkill(tunxing.name) 
    else
      return target == player and player:hasSkill(tunxing.name) 
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local mark = type(player:getMark(tunxing.name)) == "table" and player:getMark(tunxing.name) or {}
    if #mark > 0 then
      for _, s in ipairs(mark) do
        room:handleAddLoseSkills(player,"-"..s)
      end
    end
    local lords = {}
    local gp = table.simpleClone(Fk:getAllGenerals())
    table.shuffle(gp)
    for _, general in ipairs(gp) do
      if #lords >= 3 then break end
      for _, s in ipairs(general.skills) do
        if s.lordSkill then
          table.insertIfNeed(lords,general.name)
        end
      end
    end
    local choice
    local result = player.room:askForCustomDialog(player, tunxing.name,
      "packages/utility/qml/ChooseGeneralsAndChoiceBox.qml", {
        lords,
        {"OK"},
        "选择一张武将牌获得其除限定技、主公技外的所有技能",
      })
      if result ~= "" then
        local reply = json.decode(result)
        choice = reply.cards[1]
      end
    mark = {}
    if choice and Fk.generals[choice] ~= nil then
    local skills = table.simpleClone(Fk.generals[choice].skills)
    local skills2 = table.simpleClone(Fk.generals[choice].other_skills)
    if #skills2 > 0 then
      for _, s in ipairs(skills2) do
        table.insertIfNeed(skills,s)
      end
    end
    for _, s in ipairs(skills) do
        if not (table.contains({Skill.Limited, Skill.Wake, Skill.Quest},s.frequency) or s.lordSkill) and not player:hasSkill(s.name) then
          table.insertIfNeed(mark,s.name)
        end
    end
    room:notifySkillInvoked(player,tunxing.name)
    player:broadcastSkillInvoke(tunxing.name)
    room:setPlayerMark(player,tunxing.name,mark)
    room:handleAddLoseSkills(player,table.concat(mark,"|"))
    end
  end,
})
--]]
return tunxing